"""
@name : 13.协程
@author : wenyao
@projectname: xsfh
"""
# def a():
#     i = 1
#     while i<101:
#         yield i
#         i += 1
#
# # b = a()
# # for i in b:
# #     print(i)
# b = a()
# print(next(b))
# print("xxxxxxxxxxxxxx")
# print(next(b))

#异步编程
import asyncio

async  def func1():
    print(1)
    await asyncio.sleep(2)
    print(2)

async def func2():
    print(3)
    await asyncio.sleep(2)
    print(4)

#创建任务列表
tasks = [
    asyncio.ensure_future(func1()),
    asyncio.ensure_future(func2())
]
#事件循环
loop = asyncio.get_event_loop()
#运行
loop.run_until_complete(asyncio.wait(tasks))
